/**
 * By Alpha
 * Author: alixez <alixe.z@foxmail.com>
 * Date: 2017/11/16
 */

import moment from 'moment';
import Mock from 'mockjs';
import { mockAPIPrefix } from "../src/config/api";

const generateNO = () => moment().format('YYYYMMDDss');

let memberListData = Mock.mock({
  'data|80-100': [
    {
      id: '@id',
      memberNO: generateNO,
      name: '@cname',
      mobile: /^1[34578]\d{9}$/,
      'gender|0-2': 0,
      department: {
        name: '办公室',
      },
      roles: '角色',
      job: '干事',
      email: '@email',
      createTime: '@datetime',
      avatar () {
        return Mock.Random.image('100x100', Mock.Random.color(), '#757575', 'png', this.name.substr(0, 1));
      },
    },
  ],
});


let members = memberListData.data;

export default {
  [`GET ${mockAPIPrefix}/member/list`] (req, res) {

    let { pageSize, page, ...otherArgs } = req.query;
    pageSize = pageSize || 10;
    page = page || 1;

    // console.log(members);
    res.status(200).json({
      data: members.slice((page - 1) * pageSize, page * pageSize),
      total: members.length,
    });
  },

  [`GET ${mockAPIPrefix}/member/details`] (req, res) {

    let { id } = req.query;

    const currentMember = members.find(_ => _.id === id);

    res.status(200).json({
      member: currentMember,
    });
  },

};
